Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] Value list exception support for all rule types #133254

Merged
merged 64 commits into from
Sep 19, 2022

Conversation

dplumlee
Copy link
Contributor

@dplumlee dplumlee commented May 31, 2022

Summary

Addresses https://github.com/elastic/security-team/issues/3076 (internal)

Overview

Adds value list exception support to every rule type with a few caveats. Structurally, this PR adds the definition of a "small" list that is able to be included directly in the rule executor's elasticsearch query instead of filtering out large lists in the post-execution process. This allows us to add value list exceptions for every rule type given some constraints, but still keep the post-execution logic and not degrade any current expected functionality.

Definitions

  • "Small" value lists are defined as Keyword, IP value, or IP range* type lists that are under 65,536 items
  • Small value lists are able to be used for every rule type
  • Large value lists are defined as Keyword, IP value, or IP range* type lists that are over 65,536 items OR any sized text type list
  • Large value lists are only able to be used for Query, Saved Query, ML, and Threat match rule types
  • IP range value lists have two value types: slash notation (127.0.0.1/32) and dash notation (127.0.0.1-127.0.0.4)

Caveats

  • IP range value lists are considered small only if the slash notation values are under 65,536, dash notation values require us to build the exception clauses differently and thus are limited to 200 for a small list size
  • Text type value lists are currently not supported by small value lists

value_list_exceptions_flowchart (1)

Refactoring

This PR also restructures quite a bit of code/packages due to the refactoring of the exception filter builder. By moving the exception builder logic to the backend, we have implemented a new API that returns the results previously done by the common package logic.

Screenshots

image

Screen Shot 2022-09-15 at 4 37 22 PM

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@dplumlee dplumlee force-pushed the value-list-exceptions branch from eb75d87 to 5a40fba Compare June 1, 2022 19:54
@dplumlee dplumlee self-assigned this Jun 1, 2022
@dplumlee dplumlee force-pushed the value-list-exceptions branch from 5a40fba to 796c490 Compare June 27, 2022 22:06
@dplumlee dplumlee added Team:Detections and Resp Security Detection Response Team Feature:Rule Exceptions Security Solution Detection Rule Exceptions area Feature:Detection Alerts Security Solution Detection Alerts Feature Team:Detection Alerts Security Detection Alerts Area Team v8.4.0 release_note:feature Makes this part of the condensed release notes labels Jun 27, 2022
@dplumlee dplumlee force-pushed the value-list-exceptions branch 2 times, most recently from 1e4e90b to bd0cb51 Compare July 20, 2022 00:12
@dplumlee dplumlee force-pushed the value-list-exceptions branch from 9cebeb2 to 75f28fe Compare August 8, 2022 20:00
@dplumlee dplumlee force-pushed the value-list-exceptions branch 2 times, most recently from f49bdc6 to 1eb6893 Compare August 16, 2022 20:31
@dplumlee dplumlee added v8.5.0 ci:cloud-deploy Create or update a Cloud deployment and removed v8.4.0 labels Aug 16, 2022
@dplumlee dplumlee force-pushed the value-list-exceptions branch from 7b99cca to eec67c2 Compare August 25, 2022 17:29
@dplumlee
Copy link
Contributor Author

@elasticmachine merge upstream

@dplumlee dplumlee force-pushed the value-list-exceptions branch from 346bb73 to a9f5bf5 Compare August 30, 2022 03:40
@dplumlee
Copy link
Contributor Author

@elasticmachine merge upstream

@dplumlee dplumlee force-pushed the value-list-exceptions branch from 6aa3509 to 5e52a7b Compare August 30, 2022 18:38
@dplumlee dplumlee removed the ci:cloud-deploy Create or update a Cloud deployment label Aug 30, 2022
@dplumlee
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@marshallmain marshallmain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good. Lots of async and awaits to remove once getQueryFilter on the server side is made sync again, I commented on a few but there are a lot so I stopped commenting on all of them.

Code review only so far, will test next.

Copy link
Contributor

@yctercero yctercero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM! Left a few nits. Could some integration tests be added for the find_list and find_small_list route that touch on these use cases?

Integration tests live here: x-pack/test/lists_api_integration/security_and_spaces/tests

Copy link
Contributor

@marshallmain marshallmain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost done

Copy link
Contributor

@marshallmain marshallmain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

) => {
if (unprocessedExceptions.length > 0) {
const exceptionNames = unprocessedExceptions.map((exception) => exception.name);
ruleExecutionLogger.warn(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use logStatusChange here instead of warn so that the warning is written to the rule status SO and shows up in the UI. We also need to return whether or not a warning was written to the security rule type wrapper so it doesn't call logStatusChange again and overwrite the warning with success at the end of execution. This can be done as a follow up.

Copy link
Contributor

@yctercero yctercero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for adding the integration tests!

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
lists 309 312 +3
securitySolution 3077 3081 +4
total +7

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/securitysolution-autocomplete 37 41 +4
@kbn/securitysolution-io-ts-list-types 457 492 +35
@kbn/securitysolution-list-api 60 64 +4
@kbn/securitysolution-list-constants 13 17 +4
@kbn/securitysolution-list-hooks 42 47 +5
@kbn/securitysolution-list-utils 187 149 -38
lists 90 92 +2
total +16

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
lists 149.0KB 151.5KB +2.5KB
securitySolution 6.4MB 6.4MB +1.6KB
total +4.1KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
lists 49 50 +1
Unknown metric groups

API count

id before after diff
@kbn/securitysolution-autocomplete 52 56 +4
@kbn/securitysolution-io-ts-list-types 470 505 +35
@kbn/securitysolution-list-api 61 67 +6
@kbn/securitysolution-list-constants 28 33 +5
@kbn/securitysolution-list-hooks 53 58 +5
@kbn/securitysolution-list-utils 235 191 -44
lists 202 204 +2
total +13

ESLint disabled line counts

id before after diff
@kbn/securitysolution-list-api 5 6 +1

Total ESLint disabled count

id before after diff
@kbn/securitysolution-list-api 5 6 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @dplumlee

@dplumlee dplumlee merged commit 51699fa into elastic:main Sep 19, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Sep 19, 2022
@dplumlee dplumlee deleted the value-list-exceptions branch September 19, 2022 21:20
@peluja1012 peluja1012 changed the title [Security Solution] Value list exceptions [Security Solution] Value list exception support for all rule types Oct 5, 2022
kibanamachine added a commit that referenced this pull request Nov 28, 2022
…tions to use parameters (#145889) (#146414)

# Backport

This will backport the following commits from `main` to `8.5`:
- [[Security Solution][Investigations][Timeline] - Update getExceptions
to use parameters
(#145889)](#145889)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Michael
Olorunnisola","email":"[email protected]"},"sourceCommit":{"committedDate":"2022-11-28T15:08:48Z","message":"[Security
Solution][Investigations][Timeline] - Update getExceptions to use
parameters (#145889)\n\n## Summary\r\n\r\nFixes:
https://github.com/elastic/kibana/issues/136772\r\n\r\nThe issue was
introduced by a couple of
changes:\r\n\r\nFirst:\r\nhttps://github.com//pull/136163/files#diff-02d33a1ed6679f7775dc01941ca21b085d7c008ecffe5e029f5967407a5e5b13L23\r\nin
8.4.\r\n\r\nThe bug: A filter on the timeline UI relied on the
`exceptions_list`\r\nfield provided on `_source` to auto-generate a
filter when investigating\r\nin timeline labelled `Not Exceptions` which
would filter out the\r\nexceptions from the timeline. This PR resolves
that issue by pulling the\r\n`exceptions_list` field from
`kibana.alert.rule.parameters`.\r\n\r\nSecond:\r\nhttps://github.com//pull/133254/files#diff-0f69b69fd9cefef6ed04a048d7df86b7e385e816bdf17309212437dc3f69726cL74\r\n\r\nThe
filter actually stopped being passed to timeline entirely because
of\r\nthe above change.\r\n\r\nWith the fixes in
place:\r\n\r\n\r\nhttps://user-images.githubusercontent.com/17211684/203111748-7a0c2eb5-a46f-4f88-9d77-3628204625ac.mov","sha":"b32c8b9df89188cdcb149bd1d9494d3f99999ad6","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","backport","release_note:fix","Team:Threat
Hunting:Investigations","v8.5.0","v8.6.0","v8.7.0"],"number":145889,"url":"https://github.com/elastic/kibana/pull/145889","mergeCommit":{"message":"[Security
Solution][Investigations][Timeline] - Update getExceptions to use
parameters (#145889)\n\n## Summary\r\n\r\nFixes:
https://github.com/elastic/kibana/issues/136772\r\n\r\nThe issue was
introduced by a couple of
changes:\r\n\r\nFirst:\r\nhttps://github.com//pull/136163/files#diff-02d33a1ed6679f7775dc01941ca21b085d7c008ecffe5e029f5967407a5e5b13L23\r\nin
8.4.\r\n\r\nThe bug: A filter on the timeline UI relied on the
`exceptions_list`\r\nfield provided on `_source` to auto-generate a
filter when investigating\r\nin timeline labelled `Not Exceptions` which
would filter out the\r\nexceptions from the timeline. This PR resolves
that issue by pulling the\r\n`exceptions_list` field from
`kibana.alert.rule.parameters`.\r\n\r\nSecond:\r\nhttps://github.com//pull/133254/files#diff-0f69b69fd9cefef6ed04a048d7df86b7e385e816bdf17309212437dc3f69726cL74\r\n\r\nThe
filter actually stopped being passed to timeline entirely because
of\r\nthe above change.\r\n\r\nWith the fixes in
place:\r\n\r\n\r\nhttps://user-images.githubusercontent.com/17211684/203111748-7a0c2eb5-a46f-4f88-9d77-3628204625ac.mov","sha":"b32c8b9df89188cdcb149bd1d9494d3f99999ad6"}},"sourceBranch":"main","suggestedTargetBranches":["8.5","8.6"],"targetPullRequestStates":[{"branch":"8.5","label":"v8.5.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/145889","number":145889,"mergeCommit":{"message":"[Security
Solution][Investigations][Timeline] - Update getExceptions to use
parameters (#145889)\n\n## Summary\r\n\r\nFixes:
https://github.com/elastic/kibana/issues/136772\r\n\r\nThe issue was
introduced by a couple of
changes:\r\n\r\nFirst:\r\nhttps://github.com//pull/136163/files#diff-02d33a1ed6679f7775dc01941ca21b085d7c008ecffe5e029f5967407a5e5b13L23\r\nin
8.4.\r\n\r\nThe bug: A filter on the timeline UI relied on the
`exceptions_list`\r\nfield provided on `_source` to auto-generate a
filter when investigating\r\nin timeline labelled `Not Exceptions` which
would filter out the\r\nexceptions from the timeline. This PR resolves
that issue by pulling the\r\n`exceptions_list` field from
`kibana.alert.rule.parameters`.\r\n\r\nSecond:\r\nhttps://github.com//pull/133254/files#diff-0f69b69fd9cefef6ed04a048d7df86b7e385e816bdf17309212437dc3f69726cL74\r\n\r\nThe
filter actually stopped being passed to timeline entirely because
of\r\nthe above change.\r\n\r\nWith the fixes in
place:\r\n\r\n\r\nhttps://user-images.githubusercontent.com/17211684/203111748-7a0c2eb5-a46f-4f88-9d77-3628204625ac.mov","sha":"b32c8b9df89188cdcb149bd1d9494d3f99999ad6"}}]}]
BACKPORT-->

Co-authored-by: Michael Olorunnisola <[email protected]>
kibanamachine added a commit that referenced this pull request Nov 28, 2022
…tions to use parameters (#145889) (#146415)

# Backport

This will backport the following commits from `main` to `8.6`:
- [[Security Solution][Investigations][Timeline] - Update getExceptions
to use parameters
(#145889)](#145889)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Michael
Olorunnisola","email":"[email protected]"},"sourceCommit":{"committedDate":"2022-11-28T15:08:48Z","message":"[Security
Solution][Investigations][Timeline] - Update getExceptions to use
parameters (#145889)\n\n## Summary\r\n\r\nFixes:
https://github.com/elastic/kibana/issues/136772\r\n\r\nThe issue was
introduced by a couple of
changes:\r\n\r\nFirst:\r\nhttps://github.com//pull/136163/files#diff-02d33a1ed6679f7775dc01941ca21b085d7c008ecffe5e029f5967407a5e5b13L23\r\nin
8.4.\r\n\r\nThe bug: A filter on the timeline UI relied on the
`exceptions_list`\r\nfield provided on `_source` to auto-generate a
filter when investigating\r\nin timeline labelled `Not Exceptions` which
would filter out the\r\nexceptions from the timeline. This PR resolves
that issue by pulling the\r\n`exceptions_list` field from
`kibana.alert.rule.parameters`.\r\n\r\nSecond:\r\nhttps://github.com//pull/133254/files#diff-0f69b69fd9cefef6ed04a048d7df86b7e385e816bdf17309212437dc3f69726cL74\r\n\r\nThe
filter actually stopped being passed to timeline entirely because
of\r\nthe above change.\r\n\r\nWith the fixes in
place:\r\n\r\n\r\nhttps://user-images.githubusercontent.com/17211684/203111748-7a0c2eb5-a46f-4f88-9d77-3628204625ac.mov","sha":"b32c8b9df89188cdcb149bd1d9494d3f99999ad6","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","backport","release_note:fix","Team:Threat
Hunting:Investigations","v8.5.0","v8.6.0","v8.7.0"],"number":145889,"url":"https://github.com/elastic/kibana/pull/145889","mergeCommit":{"message":"[Security
Solution][Investigations][Timeline] - Update getExceptions to use
parameters (#145889)\n\n## Summary\r\n\r\nFixes:
https://github.com/elastic/kibana/issues/136772\r\n\r\nThe issue was
introduced by a couple of
changes:\r\n\r\nFirst:\r\nhttps://github.com//pull/136163/files#diff-02d33a1ed6679f7775dc01941ca21b085d7c008ecffe5e029f5967407a5e5b13L23\r\nin
8.4.\r\n\r\nThe bug: A filter on the timeline UI relied on the
`exceptions_list`\r\nfield provided on `_source` to auto-generate a
filter when investigating\r\nin timeline labelled `Not Exceptions` which
would filter out the\r\nexceptions from the timeline. This PR resolves
that issue by pulling the\r\n`exceptions_list` field from
`kibana.alert.rule.parameters`.\r\n\r\nSecond:\r\nhttps://github.com//pull/133254/files#diff-0f69b69fd9cefef6ed04a048d7df86b7e385e816bdf17309212437dc3f69726cL74\r\n\r\nThe
filter actually stopped being passed to timeline entirely because
of\r\nthe above change.\r\n\r\nWith the fixes in
place:\r\n\r\n\r\nhttps://user-images.githubusercontent.com/17211684/203111748-7a0c2eb5-a46f-4f88-9d77-3628204625ac.mov","sha":"b32c8b9df89188cdcb149bd1d9494d3f99999ad6"}},"sourceBranch":"main","suggestedTargetBranches":["8.5","8.6"],"targetPullRequestStates":[{"branch":"8.5","label":"v8.5.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/145889","number":145889,"mergeCommit":{"message":"[Security
Solution][Investigations][Timeline] - Update getExceptions to use
parameters (#145889)\n\n## Summary\r\n\r\nFixes:
https://github.com/elastic/kibana/issues/136772\r\n\r\nThe issue was
introduced by a couple of
changes:\r\n\r\nFirst:\r\nhttps://github.com//pull/136163/files#diff-02d33a1ed6679f7775dc01941ca21b085d7c008ecffe5e029f5967407a5e5b13L23\r\nin
8.4.\r\n\r\nThe bug: A filter on the timeline UI relied on the
`exceptions_list`\r\nfield provided on `_source` to auto-generate a
filter when investigating\r\nin timeline labelled `Not Exceptions` which
would filter out the\r\nexceptions from the timeline. This PR resolves
that issue by pulling the\r\n`exceptions_list` field from
`kibana.alert.rule.parameters`.\r\n\r\nSecond:\r\nhttps://github.com//pull/133254/files#diff-0f69b69fd9cefef6ed04a048d7df86b7e385e816bdf17309212437dc3f69726cL74\r\n\r\nThe
filter actually stopped being passed to timeline entirely because
of\r\nthe above change.\r\n\r\nWith the fixes in
place:\r\n\r\n\r\nhttps://user-images.githubusercontent.com/17211684/203111748-7a0c2eb5-a46f-4f88-9d77-3628204625ac.mov","sha":"b32c8b9df89188cdcb149bd1d9494d3f99999ad6"}}]}]
BACKPORT-->

Co-authored-by: Michael Olorunnisola <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Detection Alerts Security Solution Detection Alerts Feature Feature:Rule Exceptions Security Solution Detection Rule Exceptions area release_note:feature Makes this part of the condensed release notes Team:Detection Alerts Security Detection Alerts Area Team Team:Detections and Resp Security Detection Response Team v8.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants